package com.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.model.Admin;
import com.service.AdminService;
import com.util.Result;
import com.util.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin("*")
public class AdminLoginController {
    @Autowired
    private AdminService adminService;

    /**
     * 管理员登录接口
     */
    @PostMapping("/adminLogin")
    public Result login(@RequestBody Admin admin) {
        QueryWrapper<Admin> wrapper = new QueryWrapper<>();
        wrapper.eq("account", admin.getAccount())
                .eq("password", admin.getPassword());
        Admin loginAdmin = adminService.getOne(wrapper);
        if (loginAdmin != null){
            return new Result("200","登录成功",1,null);
        } else {
            return new Result(ResultEnum.USERNAME_PASSWORD_ERROR,0,null);
        }
    }
}
